Repository navigation
Conversation
Use stack buffers with binary.AppendVarint in Pathway.EncodeBase64 and base64.StdEncoding.Decode in DecodeBase64. Replace context.WithValue with a dedicated pathwayContext type to avoid boxing Pathway into any. Benchmarks (5-run medians, Apple M5 Pro, Go 1.27.4): - BenchmarkEncodeBase64: 41.4 -> 22.2 ns/op (-46.4%), 56 -> 32 B/op, 2 -> 1 alloc/op - BenchmarkDecodeBase64: 54.6 -> 38.2 ns/op (-30.0%), 136 -> 80 B/op, 3 -> 1 alloc/op - BenchmarkSetCheckpoint: 216.6 -> 205.2 ns/op (-5.3%), 400 -> 368 B/op, 4 -> 3 allocs/op
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 1 Pipeline job failed
ℹ️ InfoNo other issues found (see more)🧪 All tests passed 🎯 Code Coverage (details) Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: eebe8cb | Docs | View more details | Give us feedback! |
There was a problem hiding this comment.
Wrapping a pathway context in a cancellation, value, or span context makes each subsequent pathway lookup allocate a fresh boxed Pathway, introducing a performance regression on repeated lookups.
🤖 Bits Code Review · Commit eebe8cb
|
|
||
| func (c *pathwayContext) Value(key any) any { | ||
| if key == activePathwayKey { | ||
| return c.pathway |
There was a problem hiding this comment.
Avoid boxing the pathway on every wrapped-context lookup
When a pathway context is wrapped with context.WithCancel, context.WithValue, or tracer.ContextWithSpan, PathwayFromContext misses its direct assertion and reaches this return. Converting c.pathway to any allocates a fresh boxed copy on every lookup; previously, context.WithValue reused the value boxed during insertion. Repeated injection, merging, and checkpoint lookups therefore incur an additional allocation, undermining this hot-path optimization. Return an internal reference here and update PathwayFromContext to dereference it.
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
BenchmarksBenchmark execution time: 2026-11-25 16:04:40 Comparing candidate commit eebe8cb in PR branch Found 3 performance improvements and 0 performance regressions! Performance is the same for 413 metrics, 0 unstable metrics.
|
What does this PR do?
Reduces heap allocations and latency on the Data Streams Monitoring base64 propagation and context hot path in
internal/datastreams:Pathway.EncodeBase64encodes into stack buffers usingbinary.AppendVarintandbase64.StdEncoding.Encode. It allocates only the returned string.DecodeBase64decodes headers up to 64 bytes into a stack buffer instead of callingbase64.StdEncoding.DecodeString.ContextWithPathwayreturns a dedicatedpathwayContexttype instead ofcontext.WithValue. This avoids boxingPathwayintoanyand givesPathwayFromContexta direct type-assertion fast path.EncodeBase64,DecodeBase64, andpathwayHash.Motivation
Production Go Continuous Profiler data (
language:go env:prod) showsdatastreams.ExtractFromBase64Carrier,datastreams.InjectToBase64Carrier,Pathway.EncodeBase64, andContextWithPathwayas top heap allocation sources indd-trace-go.Benchmarks (5-run medians, Apple M5 Pro, Go 1.27.4):
BenchmarkEncodeBase64BenchmarkDecodeBase64BenchmarkSetCheckpointVerified with
go test -race ./internal/datastreams/... ./datastreams/...andmake lint/errlog.Reviewer Checklist